package leetcode.code1487;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public String[] getFolderNames(String[] names) {
		Map<String, Integer> map = new HashMap<>();
		Set<String> created = new HashSet<>();
		String[] ans = new String[names.length];
		for (int i = 0; i < names.length; i++) {
			String name = names[i];
			if (created.contains(name)) {
				int id = map.getOrDefault(name, 1);
				while (created.contains(name + "(" + id + ")")) {
					id++;
				}
				map.put(name, id + 1);
				name += "(" + id + ")";
			} else {
				map.put(name, 1);
			}
			ans[i] = name;
			created.add(name);
		}
		return ans;
	}

	@Override
	public void debug4() {
		H.compare(H.str2array2("[\"kaido\",\"kaido(1)\",\"kaido(2)\",\"kaido(1)(1)\",\"kaido(2)(1)\"]"),
				this.getFolderNames(H.str2array2("[\"kaido\",\"kaido(1)\",\"kaido\",\"kaido(1)\",\"kaido(2)\"]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
